export default {
  data () {
    return {
      traderReportDetailRow: {
        pageNumber:1,
        pageSize: 10,
        total: 0,
        searchParams: {},
        searchList: [
          { index: 0, isShow: false, type: 'text', name: 'couponName', text: '优惠券名称', value: '' }
        ],
        theadsInfo: [
          { index: 0, isShow: false, prop: 'reno', text: '序号', width: 68 },
          { index: 1, isShow: false, prop: 'reportDate', text: '日期', minWidth: 110 },
          { index: 2, isShow: false, prop: 'couponCode', text: '优惠券', minWidth: 155 },
          { index: 3, isShow: false, prop: 'couponName', text: '优惠券名称', minWidth: 155 },
          // { index: 4, isShow: false, prop: 'balanceName', text: '券类型', minWidth: 100},
          { index: 4, isShow: false, prop: 'billStatus', text: '账单状态', minWidth: 100 },
          { index: 5, isShow: false, prop: 'settleNum', text: '结算数量', minWidth: 110 },
          { index: 6, isShow: false, prop: 'settleMoney', text: '结算金额', minWidth: 110 }
        ],
        tbodysInfo: []
      },
      traderReportRow:{}
    }
  },
  created () {
    
  },
  methods: {
    getList () {
      this.getTraderReport(this.searchParams);
    },
    getTraderReport (aparams) {//查询列表
      let self = this,
          params = {
            page: this.pageNumber,
            rp: this.pageSize
          };
      params = $.extend({}, params, aparams, self.otherParams);
      API.report.GetTraderReportData(params)
          .then(res => {
            let data = res.data,
                list = data.rows;
            self.tbodysInfo = list;
            self.total = data.total;
          }, err => {})
    },
    reCreate(){
       let self = this;
       var params = {
        startDate: self.searchList[0].value[0],
        endDate: self.searchList[0].value[1],
        traderName: self.searchList[1].value,
       };

      //校验逻辑
      if(params.startDate == null || params.endDate == null){
        self.showToast("请选择时间区间",2);
        return;
      }
      let s1 = params.startDate.getTime(),s2 = params.endDate.getTime();
      let total = (s2 - s1)/1000;
      let day = parseInt(total / (24*60*60));//计算整数天数
      if(day>30){
        self.showToast("时间区间不能超过30天",2);
        return;
      }
      params.startDate = params.startDate.Format("yyyy-MM-dd")
      params.endDate = params.endDate.Format("yyyy-MM-dd")
      API.report.ReCreateReport(params)
        .then(res => {
          let data = res.data;
          if(res.status==1){
            self.showToast("操作成功",1);
          }else{
            self.showToast(res.message,2);
          }
        }, err => {})
    },
    exportData(){//导出
      let self = this;
      this.showDialog("是否确认导出记录？",[],function(){
        let params = {
        };
        params = $.extend({}, params, self.otherParams, self.searchParams);
        self.toExportAsync('report/trader/exportTraderReport.do', params);
      },"温馨提示",function(){
        //取消时不操作
      });
    },
    toOpenTraderReportDetail(row,modalName){//打开详情
      this.traderReportRow = row;
      this.toOpenModal(modalName);
      this.getTraderReportDetailList(row);
    },
    getTraderReportDetailList(aparams){//获取详情列表
      let self = this,
      params = {
        "id":this.traderReportRow.id,
        page: this.traderReportDetailRow.pageNumber,
        rp: this.traderReportDetailRow.pageSize
      };
      params = $.extend({}, params, aparams);
      API.report.GetTraderDayReportDetailData(params)
          .then(res => {
            let data = res.data,
                list = data.rows;
            self.traderReportDetailRow.tbodysInfo = list;
            self.traderReportDetailRow.total = data.total;
            self.traderReportDetailRow.pageNumber = data.page;
          }, err => {})
    },
    toSearchTraderReportDetail(params){//弹出窗的列表搜索方法
      this.traderReportDetailRow.pageNumber = 1;
      this.traderReportDetailRow.searchParams = $.extend({}, params);
      this.getTraderReportDetailList(params);
    },
    auditTraderReport(row){//审核
      let self = this;
      this.showDialog("是否确定要审批该商家的券报表？",[],function(){
        API.report.AuditTraderDayReport({"id":row.id}).then(res => {
          if(res.status==1){
            self.getList();
            self.showToast("操作成功",1);
          }else{
            self.showToast("操作失败",2);
          }
        }, err =>{});
      },"温馨提示",function(){
        //取消时不操作
      });
    },
    confirmCashSettle(row){//确认现金收款
      let self = this;
      this.showDialog("是否确定要现金结算未支付的商家账单？",[],function(){
        API.report.ConfirmSettleTraderDayReport({"id":row.id}).then(res => {
          if(res.status==1){
            self.getList();
            self.showToast("操作成功",1);
          }else{
            self.showToast("操作失败",2);
          }
        }, err =>{});
      },"温馨提示",function(){
        //取消时不操作
      });
    },
    filterMultiCheck (selectionArr) {//必须定义获取多列的方法
      let result = [];
        selectionArr.map((item)=>{
          result.push(item.id);
        });
      return result;
    },
    // Modal里的分页方法
    getReportDetailPagination (curPage, pageSize) {
      this.traderReportDetailRow.pageNumber = curPage;
      this.traderReportDetailRow.pageSize = pageSize ? pageSize : this.traderReportDetailRow.pageSize;
      this.getTraderReportDetailList(this.traderReportDetailRow.searchParams);
    }
  }
}